home *** CD-ROM | disk | FTP | other *** search
/ Gekkan Dennou Club 140 / Gekkan Dennou Club - 2000.1 Vol. 140 (Japan).7z / Gekkan Dennou Club - 2000.1 Vol. 140 (Japan) (Track 1).bin / tools / dshell / dsh333bs.lzh / menu.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-07-11  |  5.8 KB  |  309 lines

  1. /*
  2.     dshell    v3
  3.  
  4.     メニューや情報表示など
  5. */
  6.  
  7.  
  8. #include    "dsh.h"
  9.  
  10. typedef struct {
  11.     short dx;    /* 表示開始座標offset */
  12.     short dy;    /* 表示開始座標offset */
  13.     short wd;    /* 表示文字列幅(半角) */
  14.     char *mes;    /* 表示文字列 */
  15. } SSLSTRCT;
  16.  
  17. static int ssl_sub(int , int , SSLSTRCT *);
  18. static int setscrlin(void);
  19.  
  20.  
  21. /*
  22.     menu_sx:[MENU]メニューのX始め桁
  23. */
  24. void 
  25. menu(int menu_sx)
  26. {
  27.     static const char *contents[] =
  28.     {
  29.         "テキスト印刷",
  30.         "簡易操作説明",
  31.         "音楽 演奏開始",
  32.         "音楽   一時停止",
  33.         "音楽   演奏再開",
  34.         "改頁行数",
  35.         "Cursor-Speed Switch",    /* ver 2.3d */
  36.         "Joystick-Mouse Switch",    /* ver 2.3a */
  37.         "Keyboard-Mouse Switch",    /* ver 2.3a */
  38.         "Realtime-Scroll-Window Size"    /* ver 3.10b */
  39.     };
  40. #define    CM    (sizeof(contents) / sizeof(contents[0]))    /* メニュー項目数 */
  41.  
  42.     int dm, bl, br;
  43.     int i;
  44.     int x, y;
  45.     int s, ss = -1;
  46.     char buf[96];
  47.     const int cwidth = CWIDTH;
  48.  
  49.     void JoyMouseSwitch(void);
  50.     void KeyMouseSwitch(void);
  51.     void CSpdUpSwitch(void);
  52.  
  53.     msarea((cwidth - 40) * 8, 472 - CM * 16, (cwidth - 2) * 8 - 1, 511);
  54.     B_COLOR(5);
  55.     win_frame(cwidth - 41, 27 - CM, cwidth - 3, 30, 29 - CM, menu_sx - 1);
  56.  
  57.     B_COLOR(7);
  58.     B_LOCATE(cwidth - 39, 28 - CM);
  59.     B_PRINT("[ MENU ]  Select Line");
  60.     B_COLOR(3);
  61.     for (i = 0; i < CM; i++) {
  62.         B_LOCATE(cwidth - 39, 30 - (CM - i));
  63.         sprintf(buf, "%2d. %s", CM - i, contents[i]);
  64.         B_PRINT(buf);
  65.     }
  66.  
  67.     /*
  68.         ★KEY/JOYマウス現在の使用状態(v2.3a,v2.3d)
  69.         下の6行は、メニューの追加・削除の際、
  70.         Y表示座標を補正のこと。
  71.     */
  72.     B_LOCATE(cwidth - 26, 30 - (CM - 5));
  73.     sprintf(buf, "%2d", scrlin);
  74.     B_PRINT(buf);
  75.     B_LOCATE(cwidth - 15, 30 - (CM - 6));
  76.     sprintf(buf, "%s", (CSpdUp) ? "HIGH" : "NORMAL");
  77.     B_PRINT(buf);
  78.     B_LOCATE(cwidth - 13, 30 - (CM - 7));
  79.     sprintf(buf, "%s", (Jflg) ? "ON" : "OFF");
  80.     B_PRINT(buf);
  81.     B_LOCATE(cwidth - 13, 30 - (CM - 8));
  82.     sprintf(buf, "%s", (Kflg) ? "ON" : "OFF");
  83.     B_PRINT(buf);
  84.     B_LOCATE(cwidth - 7, 30 - (CM - 9));
  85.     sprintf(buf, "%s", (Rwin_len == RW_FULL) ? "FULL" : "HALF");
  86.     B_PRINT(buf);
  87.  
  88.     /*
  89.     !    いったん離されるのを待つ
  90.     */
  91.     wait_mb_off();
  92.  
  93.  
  94.     do {
  95.         p_time(0);
  96.         dmspos(&x, &y);
  97.         if ((30 - CM) * 16 < y && y < 480) {
  98.             s = y / 16 - 30 + CM;
  99.         } else {
  100.             s = -1;
  101.         }
  102.         if (s != ss) {
  103.             if (s != -1) {
  104.                 B_COLOR(9);
  105.                 B_LOCATE(cwidth - 35, 30 - (CM - s));
  106.                 B_PRINT(contents[s]);
  107.             }
  108.             B_COLOR(3);
  109.             if (ss != -1) {
  110.                 B_LOCATE(cwidth - 35, 30 - (CM - ss));
  111.                 B_PRINT(contents[ss]);
  112.             }
  113.         }
  114.         ss = s;
  115.         dmsstat(&dm, &dm, &bl, &br);
  116.     } while (!(bl || br));
  117.     if (br == -1) {
  118.         s = -1;        /* キャンセル */
  119.     }
  120.  
  121.  
  122.     if (s < CM) {
  123.         switch (s) {
  124.         case 0:
  125.             d_print();
  126.             break;    /* 89.07.13 */
  127.         case 1:
  128.             onlinemanual();
  129.             break;    /* ver2.30    */
  130.         case 2:
  131.             dm_play('PLAY');
  132.             break;    /* 再変更:v3.01    */
  133.         case 3:
  134.             dm_play('STOP');
  135.             break;    /* 再変更:v3.01    */
  136.         case 4:
  137.             dm_play('CONT');
  138.             break;    /* 再変更:v3.01    */
  139.         case 5:
  140.             setscrlin();
  141.             break;
  142.         case 6:
  143.             CSpdUpSwitch();
  144.             break;    /* 追加:v2.3d */
  145.         case 7:
  146.             JoyMouseSwitch();
  147.             break;    /* 追加:v2.3a */
  148.         case 8:
  149.             KeyMouseSwitch();
  150.             break;    /* 追加:v2.3a */
  151.         case 9:
  152.             Rwin_len_switch();
  153.             break;
  154.         }
  155.     }
  156.  
  157.     p_lin(lp + 29, 29);
  158.     for (i = 28; i >= 26 - CM; i--) {
  159.         p_lin(lp + i, i);
  160.     }
  161.     msarea(0, 0, GWIDTH - 1, 511);
  162.  
  163.     wait_mb_off();
  164. }
  165.  
  166.  
  167.  
  168.  
  169. /*
  170.     音楽演奏関係のシステムコールを行なう
  171.     対応するパラメータは、
  172.     PLAY
  173.     STOP
  174.     CONT
  175.     のみ(あくまでメニュー用)
  176. */
  177. int 
  178. dm_play(int param)
  179. {
  180.     int opmcall_d1(int);
  181.  
  182.     switch (param) {
  183.     case 'PLAY':
  184.         return (opmcall_d1(8));    /* 8=play */
  185.     case 'STOP':
  186.         return (opmcall_d1(10));    /* 10=stop */
  187.     case 'CONT':
  188.         return (opmcall_d1(11));    /* 11=cont */
  189.     default:
  190.         return (-1);
  191.     }
  192. }
  193.  
  194.  
  195. int
  196. Rwin_len_switch()
  197. {
  198.     Rwin_len = (Rwin_len == RW_FULL) ? RW_HALF : RW_FULL;
  199.     return (Rwin_len);
  200. }
  201.  
  202.  
  203. /*
  204.     頁スクロールの行数設定を変える
  205.  
  206.     (画面復元のことを考えないサブメニュー)
  207. */
  208. static int 
  209. ssl_sub(int x, int y, SSLSTRCT *btn)
  210. {
  211.     int i;
  212.  
  213.     for (i = 0; ; i++) {
  214.         if (btn[i].wd == 0) {
  215.             return -1;
  216.         }
  217.         if (y == btn[i].dy && x >= btn[i].dx && x < btn[i].dx + btn[i].wd) {
  218.             return i;
  219.         }
  220.     }
  221.     return -1;
  222. }
  223.  
  224.  
  225. static int
  226. setscrlin(void)
  227. {
  228.     int i;
  229.     int ox, oy;    /* メニュー枠表示開始座標 */
  230.     int wx, wy;    /* メニュー枠表示幅 */
  231.     int mx, my, ml, mr;
  232.     int tmpscrlin;
  233.     char buf[96];
  234.  
  235.     static const SSLSTRCT sslbtn[] = {
  236.         {1, 2, 6, "初期化"},    /* 0 = 初期化 */
  237.         {11, 2, 2, ""},    /* 1 = decl */
  238.         {19, 2, 2, ""},    /* 2 = incl */
  239.         {4, 3, 4, "決定"},    /* 3 = OK */
  240.         {14, 3, 4, "取消"},    /* 4 = cancel */
  241.         {0, 0, 0, ""}
  242.     };
  243.  
  244.     ox = CWIDTH - 24;
  245.     oy = 24;
  246.     wx = 22;
  247.     wy = 4;
  248.     tmpscrlin = scrlin;
  249.  
  250.     msarea(ox * 8, (oy + 2) * 16, (ox + wx) * 8 - 1, (oy + wy) * 16 - 1);
  251.  
  252.     B_COLOR(5);
  253.     win_frame(ox - 2, oy - 1, ox + wx, oy + wy, oy + 1, 0);
  254.     B_COLOR(3);
  255.  
  256.     B_LOCATE(ox, oy);
  257.     sprintf(buf, "改ページ行数(1~%d)", MAXSCRLIN);
  258.     B_PRINT(buf);
  259.  
  260.     for (i = 0; sslbtn[i].wd; i++) {
  261.         B_LOCATE(ox + sslbtn[i].dx - 1, oy + sslbtn[i].dy);
  262.         sprintf(buf, "[%s]", sslbtn[i].mes);
  263.         B_PRINT(buf);
  264.     }
  265.  
  266.     while (1) {
  267.         B_LOCATE(ox + sslbtn[1].dx + 3, oy + 2);
  268.         sprintf(buf, " %2d ", tmpscrlin);
  269.         B_PRINT(buf);
  270.         wait_mb_off();
  271.         do {
  272.             dmsstat(&mx, &my, &ml, &mr);
  273.             dmspos(&mx, &my);
  274.             p_time(0);
  275.         } while (!(ml || mr));
  276.         if (mr) {
  277.             tmpscrlin = scrlin;
  278.             break;
  279.         }
  280.         mx /= 8;
  281.         my /= 16;
  282.         switch (ssl_sub(mx - ox, my - oy, (SSLSTRCT *)&sslbtn)) {
  283.         case 0:            /* [初期化] */
  284.             tmpscrlin = DEFSCRLIN;
  285.             break;
  286.         case 1:            /* [<] */
  287.             if (--tmpscrlin < 1) {
  288.                 tmpscrlin = 1;
  289.             }
  290.             break;
  291.         case 2:            /* [>] */
  292.             if (++tmpscrlin > MAXSCRLIN) {
  293.                 tmpscrlin = MAXSCRLIN;
  294.             }
  295.             break;
  296.         case 3:            /* [決定] */
  297.             goto BREAKLOOP;
  298.         case 4:            /* [取消] */
  299.             tmpscrlin = scrlin;
  300.             goto BREAKLOOP;
  301.         }
  302.     }
  303.  
  304.       BREAKLOOP:
  305.     scrlin = tmpscrlin;
  306.  
  307.     return 0;
  308. }
  309.